<?php
declare (strict_types=1);

namespace app\index\controller;

use think\Request;

class Basic
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {

        $lcData = self::getFlayLineData(sysconf('basic.lc_data_one'), sysconf('basic.lc_data_two'));
        $lData = self::getFlayLineData(sysconf('basic.l_data_one'), sysconf('basic.l_data_two'));
        // 获取饼图数据
        $pieChartData = sysconf('basic.pie_chart_data');
        $pieChartData = explode('|',$pieChartData);
        $tempArrPie = [];
        foreach ($pieChartData as $k=>$value){
            $forTempArr = explode(',',$value);
            $tempArrPie[$k]['name'] = $forTempArr[0];
            $tempArrPie[$k]['value'] = (int)$forTempArr[1];
        }
        $chartVerticalArr = explode(',',sysconf('basic.chart_vertical'));
        foreach($chartVerticalArr as $k => $value){
            $chartVerticalArr[$k] = (int)$value;
        }
        //获取配置参数
        $data = [
            'data' => [
                'title' => sysconf('Large_screen_title'),
                'live_list' => [
                    [
                        'name' => 'videoElement',
                        'value' => sysconf('LiveRoomOne'),
                    ],
                    [
                        'name' => 'videoElement2',
                        'value' => sysconf('LiveRoomTwo'),
                    ],
                    [
                        'name' => 'videoElement3',
                        'value' => sysconf('LiveRoomThree'),
                    ],
                    [
                        'name' => 'videoElement4',
                        'value' => sysconf('LiveRoomFour'),
                    ]
                ],
                'flay_line' => [
                    'title' => sysconf('basic.flay_line_title'),
                    'fl_data_one' => explode('|', sysconf('basic.fl_data_one')),
                    'fl_data_two' => explode('|', sysconf('basic.fl_data_two')),
                ],
                'list_chart_title' => sysconf('basic.list_chart_title'),
                'list_chart' => [
                    'data' => $lcData['data'],
                    'rowNum' => $lcData['count'] - 4
                ],
                'list_title' => sysconf('basic.list_title'),
                'list' => [
                    'data' => $lData['data'],
                ],
                'pie_chart_title' => sysconf('basic.pie_chart_title'),
                'pie_chart' => [
                    'series' => [
                        [
                            'type' => 'pie',
                            'data' => $tempArrPie,
                            'insideLabel' => [
                                'show' => sysconf('basic.pie_chart_insideLabel') ? true : false
                            ],
                            'roseType' => sysconf('basic.pie_chart_roseType') ? true : false

                        ]
                    ]
                ],
                'water_chart_title' => sysconf('basic.water_chart_title'),
                'water_chart_price' => sysconf('basic.water_chart_price'),
                'water_chart' => [
                    "data" => explode(',',sysconf('basic.water_chart_value')),
                    'shape' => 'round'
                ],
                'gauge_chart' => [
                    'title' => [
                        'text' => sysconf('basic.histogram_chart'),
                        'style' => [
                            'fill' => '#fff',
                        ]
                    ],
                    'xAxis' => [
                        'name' => '第一周',
                        'data' => explode(',',sysconf('basic.chart_horizontal')),
                        'nameTextStyle' => [
                            'fill' => '#fff',
                            'fontSize' => 10,
                        ],
                        'axisLabel' => [
                            'style' => [
                                'fill' => '#fff',
                                'fontSize' => 10,
                                'rotate' => 0
                            ]
                        ]
                    ],
                    'yAxis' => [
                        'name' => '销售额',
                        'data' => 'value',
                        'nameTextStyle' => ['fill' =>
                            '#fff',
                            'fontSize' => 10
                        ],
                        'axisLabel' => [
                            'style' => [
                                'fill' => '#fff',
                                'fontSize' => 10,
                                'rotate' => 0
                            ]
                        ]
                    ],
                    'series' => [
                        [
                            'data' =>$chartVerticalArr,
                            'type' => 'bar',
                            'gradient' => [
                                'color' =>
                                    ['#37a2da', '#67e0e3']
                            ]
                        ]
                    ]

                ]
            ],
            'msg' => '获取数据成功',
            'code' => 1
        ];
        return json($data);
    }

    /**
     * 解析直播地址
     * @param $url
     */
    private static function parseLivePlayUrl($url)
    {

    }

    /**
     * 飞线图数据处理
     */
    private static function getFlayLineData($dOne, $dTwo)
    {
        $tempArr = [
            'count' => 0,
            'data' => []
        ];
        $dOne = explode(',', $dOne);
        $dTwo = explode(',', $dTwo);
        if (count($dOne) == count($dTwo)) {
            foreach ($dOne as $key => $value) {
                $tempArr['data'][$key]['name'] = $value;
                $tempArr['data'][$key]['value'] = $dTwo[$key];
            }
            $tempArr['count'] = count($dTwo);
            return $tempArr;
        }
        return false;
    }
}
